/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package VIEW;

import CONTROL.DangNhap_Control;
import MODEL.dangnhap_Model;
import javax.swing.JOptionPane;

/**
 *
 * @author CONGTHANH
 */
public class frmdangnhap extends javax.swing.JInternalFrame {

    /**
     * Creates new form frmdangnhap
     */
    public frmdangnhap() {
        initComponents();
    }
      String dialogtitle="Xác nhận";
    String message = "Bạn có chắc muốn thoát?";

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        lbtendn = new javax.swing.JLabel();
        lbmk = new javax.swing.JLabel();
        txttdn = new javax.swing.JTextField();
        txtmkdn = new javax.swing.JTextField();
        btndn = new javax.swing.JButton();
        btnex = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setTitle("Đăng Nhập");
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseExited(java.awt.event.MouseEvent evt) {
                formMouseExited(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        lbtendn.setText("Tên Đăng Nhập");

        lbmk.setText("Mật Khẩu");
        lbmk.setToolTipText("");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addComponent(lbtendn, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(lbmk, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txttdn, javax.swing.GroupLayout.DEFAULT_SIZE, 205, Short.MAX_VALUE)
                    .addComponent(txtmkdn))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lbtendn, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txttdn, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbmk, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtmkdn, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(39, Short.MAX_VALUE))
        );

        btndn.setText("Đăng Nhập");
        btndn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btndnActionPerformed(evt);
            }
        });

        btnex.setText("Thoát");
        btnex.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnexActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btndn)
                    .addComponent(btnex, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addComponent(btndn)
                .addGap(43, 43, 43)
                .addComponent(btnex)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(37, 37, 37))
        );

        jPanel1.getAccessibleContext().setAccessibleName("Thông Tin Đăng Nhập");

        pack();
    }// </editor-fold>//GEN-END:initComponents
public void khoitao(){
         txttdn.setText("");
        txtmkdn.setText("");
    }
    private void btndnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btndnActionPerformed
        // TODO add your handling code here:
         try{
            if(!txttdn.getText().equals("")&& !txtmkdn.getText().equals("")){
                String sql="select tenhienthi,quyen from DANGNHAP where tendn='"+txttdn.getText()+"' and matkhau='"+txtmkdn.getText()+"'";
                //dangnhap n=DangNhap_Control.
                         dangnhap_Model d=DangNhap_Control.dangnhap(sql);

                if(!d.getTen_hienthi().equals("")){
                    d.Ten_hienthi=d.getTen_hienthi();
                    d.quyen=d.getQuyen();
                    d.kqdn=true;

                    JOptionPane.showMessageDialog(this,"Đăng Nhập Thành Công");
                    khoitao();
                    this.setVisible(false);

                }
                else
                JOptionPane.showMessageDialog(this,"Đăng Nhập Thất Bại");
            }else
            JOptionPane.showMessageDialog(this, "Tên đăng nhập và mật khẩu không được để trống");
        }catch(Exception ex){
            JOptionPane.showMessageDialog(this, "Tên đăng nhập và mật khẩu không hợp lệ");
        }

    }//GEN-LAST:event_btndnActionPerformed

    private void btnexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnexActionPerformed
        // TODO add your handling code here:
              int x = JOptionPane.showConfirmDialog(this, message, dialogtitle, JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
    if (x == JOptionPane.YES_OPTION) 
    {
        System.exit(0);
    }
    }//GEN-LAST:event_btnexActionPerformed

    private void formMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseExited
        // TODO add your handling code here:
    }//GEN-LAST:event_formMouseExited

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btndn;
    private javax.swing.JButton btnex;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lbmk;
    private javax.swing.JLabel lbtendn;
    private javax.swing.JTextField txtmkdn;
    private javax.swing.JTextField txttdn;
    // End of variables declaration//GEN-END:variables
}
